package com.exam.controller;


import com.exam.pojo.Student;
import com.exam.service.StudentService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class StudentController {
    @Resource
    private StudentService studentService;

    @GetMapping("/student/{id}")
    public Student getAllById(@PathVariable("id") Integer studentId){
        return studentService.queryById(studentId);
    }
    @PutMapping("/student/update")
    public int updateById(@RequestBody Student student){
        return studentService.updateById(student);
    }

    @GetMapping("/manage/students/{id}/{pageNum}/{pageSize}")
    public PageInfo<Student> getAllByTea(@PathVariable("id") Integer teacherId,
                                         @PathVariable("pageNum") Integer pageNum,
                                         @PathVariable("pageSize") Integer pageSize){
        return studentService.queryStuByTeaId(teacherId,pageNum,pageSize);
    }
    @GetMapping("/manage/students/{pageNum}/{pageSize}")
    public PageInfo<Student> getAllByAdmin(@PathVariable("pageNum") Integer pageNum,
                                         @PathVariable("pageSize") Integer pageSize){
        return studentService.queryAllPage(pageNum,pageSize);
    }
    @DeleteMapping("/manage/student/delete/{id}")
    public Boolean deleteById(@PathVariable("id") Integer userId){
        return studentService.deleteByUserId(userId);
    }
    @GetMapping("/manage/students/id")
    public List<Integer> getStuId(){
        return studentService.queryStuId();
    }

    @PostMapping("/manage/student/add")
    public Boolean add(@RequestBody Student student){
        try {
            studentService.insert(student);
            return true;
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
    }
}
